#!/bin/bash

ARGS=`getopt -o d: --long directory: -n "$0" -- "$@"`
eval set -- "${ARGS}"
user_define_path=""
# 脚本接受参数 --directory user_define_path
while [[ "$1" != "" ]]; do
    case $1 in
        --directory )        shift
                             user_define_path=$1
                             ;;
        * )                  echo "Usage: ./create_dir.sh --directory <user_define_path>"
                             exit 1
    esac
    shift
done

# 检查是否提供了目录路径
if [ -z "$user_define_path" ]; then
    echo "Error: No directory path provided."
    echo "Usage: ./create_dir.sh --directory <user_define_path>"
    exit 1
fi

# 获取脚本所在的目录
script_dir=$(dirname "$0")
# 使用脚本所在目录作为根目录构建目标路径
target_dir="$script_dir/$user_define_path"


# 检查目录是否存在
if [ -d "$target_dir" ]; then
    echo "Directory '$target_dir' already exists."
else
    # 如果目录不存在，则创建它
    mkdir -p "$target_dir"
    echo "Directory '$target_dir' has been created."
fi